package com.gkzf.ai.module.crm.util.packaging;

import com.gkzf.ai.module.crm.dal.dataobject.creditReport.CreditReportBasicDO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 提取基本信息
 * 并封装/计算
 */
@Slf4j
public class CalculationBasicInfo {


    public void extractBasic(Map<String, Object> finallyMap, CreditReportBasicDO creditReportBasicDO) {
        Object o = finallyMap.get("本人信息");
        if (Objects.nonNull(o) && o instanceof List) {
            List<Map<String, String>> basicList = (List<Map<String, String>>)o;
            if (basicList.isEmpty()) {
                return;
            }
            Map<String, String> basic = basicList.get(0);
            for (Map.Entry<String, String> basicMap : basic.entrySet()) {
                String nextKey = basicMap.getKey();
                String value = basicMap.getValue();
                switch (nextKey) {
                    case "婚姻状况":
                        log.info("婚姻状况:{}", value);
                        creditReportBasicDO.setMarriageStatus(value.trim().replace(" ", ""));
                        break;
                    case "被查询者姓名":
                        log.info("被查询者姓名:{} ", value);
                        if (!StringUtils.isNotBlank(creditReportBasicDO.getName())) {
                            creditReportBasicDO.setName(value.trim().replace(" ", ""));
                        }
                        break;
                    case "被查询者证件号码":
                        log.info("被查询者证件号码:{} ", value);
                        if (!StringUtils.isNotBlank(creditReportBasicDO.getIdNumber())) {
                            creditReportBasicDO.setIdNumber(value.trim().replace(" ", ""));
                        }
                        break;
                    case "被查询者证件类型":
                        log.info("被查询者证件类型:{}", value);
                        creditReportBasicDO.setDocumentType(value.trim().replace(" ", ""));
                        break;
                    case "学历":
                        log.info("学历:{}", value);
                        creditReportBasicDO.setEducation(value.trim().replace(" ", ""));
                        break;
                    default:
                        break;

                }
            }
        }
    }
}
